<?php

class BtnBuy extends CWidget
{
    public $oRow = array();
	public $text = '';
	public $addedText = '';

    private $_html = '';

    public function init()
    {}

    public function run()
    {
        $this->_html .= '<a class="btn buy';

        if(Order::model()->getCountInCart($this->oRow->id))
            $this->_html .= ' in-cart';

        $this->_html .= '" href="';

        if(Order::model()->getCountInCart($this->oRow->id))
            $this->_html .= Yii::app()->controller->createUrl('/goods/cart/list', array());
        else
            $this->_html .= Yii::app()->controller->createUrl('/goods/cart/add', array('id' => $this->oRow->id));

        $this->_html .= '">';

        $this->_html .= Order::model()->getCountInCart($this->oRow->id) ? ($this->addedText ? $this->addedText : "Добавлено в корзину") : ($this->text ? $this->text : "Добавить в корзину");

        $this->_html .= '</a>';
    }

    public function __toString()
    {
        return $this->_html;
    }
}
